package com.cookor.poi.modules.phy.mobile;

import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.utils.ResultUtil;
import com.cookor.poi.modules.phy.entity.TEvaluate;
import com.cookor.poi.modules.phy.service.TEvaluateService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping({"/api/phy/evaluate"})
@ResponseBody
public class ApiEvaluateController extends ApiBaseController {
  @Autowired
  private TEvaluateService tEvaluateService;
  
  @RequestMapping({"/add"})
  public ResultUtil addEvaluate(HttpServletRequest request, Integer orderId, String openId, Integer star, String content, Integer noShow) {
    ResultUtil result = getResult();
    try {
      Integer tenantId = getTenantId(request);
      this.tEvaluateService.add(tenantId, orderId, openId, star, content, noShow);
    } catch (Exception e) {
      result.setCode(ResultUtil.ERROR_CODE);
      result.setError(e.getMessage());
      this.logger.error("ApiEvaluateController addEvaluate error!", e);
    } 
    return result;
  }
  
  @RequestMapping({"/list"})
  public ResultUtil EvaluateList(HttpServletRequest request, Integer doctorId) {
    ResultUtil result = getResult();
    try {
      Integer tenantId = getTenantId(request);
      if (doctorId == null)
        throw new Exception("参数错误"); 
      TEvaluate tEvaluate = new TEvaluate();
      tEvaluate.setTenantId(tenantId);
      tEvaluate.setDoctorId(doctorId);
      Page<TEvaluate> page = this.tEvaluateService.findPage(new Page(1, 3), tEvaluate);
      result.putParams("page", page);
    } catch (Exception e) {
      result.setCode(ResultUtil.ERROR_CODE);
      result.setError(e.getMessage());
      this.logger.error("ApiEvaluateController EvaluateList error!", e);
    } 
    return result;
  }
}
